// modules/introduce/pages/every-group/every-group.js
import {
  getGroupDetail
} from '@/api/introduce'

// 导入 ComponentWithStore 方法
import {
  ComponentWithStore
} from 'mobx-miniprogram-bindings'
import {
  store
} from '@/stores/store' // 引入仓库store
// 导入 store 对象
import {
  InfoStore
} from '@/stores/InfoStore'
const appInstance = getApp()
ComponentWithStore({
  data: {
    groups: [],
    groupDetail: {},
    introduction: '',
    requirement: '',
  },

  storeBindings: [{
      store: store,
      fields: ["activeTabBar"],
      actions: ["updateActive"]
    },
    {
      store: InfoStore,
      fields: ['isRegister'],
    }
  ],
  methods: {
    toLogin() {
      wx.switchTab({
        url: '/pages/schedule/schedule',
      })
      // 手动更新tabBar光标
      this.updateActive(1)
    },
    async onLoad(options) {
      const id = options.id;
      console.log("Received ID:", id);
      // 请求具体的组别信息
      const {
        data
      } = await getGroupDetail(id)
      console.log(data)
      this.setData({
        introduction: data.introduction,
        requirement: data.requirement,
        groups: appInstance.globalData.groups
      })
      // console.log(this.data.groups)

      // 查找对应的组信息
      const groupDetail = this.data.groups.find(item => item.id == id);
      this.setData({
        groupDetail: groupDetail
      })
      // console.log(this.data.groupDetail)

    },
  }


})